home *** CD-ROM | disk | FTP | other *** search
- 1 rem ==================================
- 2 rem commodares problem #44-1 :
- 3 rem added difficulty
- 4 rem solution by
- 5 rem jim lostetter
- 6 rem ==================================
- 20 input"[147]show all combinations that add up to";n
- 30 f=f+1:iff>n/2thenprintc;"combinations":end
- 40 m=f+1:l(0)=f:ls=f:gosub100
- 50 l(l)=l(l)+1:ls=ls+1:ifl(0)+f>n then30
- 60 if l>0 and l(1)>l(0) then l=0:ls=l(l):goto 50
- 70 gosub 100:ms=m:gosub 100:ms=0:ifl(l)<=m then 50
- 80 l=l+1:l(l)=m+1:ls=ls+l(l) :if ls+f<=n then 70
- 90 l=1:ls=l(l)+l(0):goto 50
- 100 rem subroutine
- 110 fs=n-ls-ms :if fs<f or fs/f<>int(fs/f) then return
- 120 for p=f to fs step f:printf;:next:ifms=0 then 140
- 130 for p=m to ms step m:print m;:next
- 140 for p=l to 0 step-1:print l(p);:next:print:c=c+1
- 150 if ms=0 then return
- 160 ms=ms+m:goto 110
-